package com.mikelouis.test.scala.proginscala.chapter27.runtime

import com.mikelouis.test.scala.proginscala.chapter27.recipe.{Browser, SimpleDatabase, StudentDatabase, Database}

/**
 * Created by yuazhu on 2/25/2015.
 */
object GotApples {
  def main(args: Array[String]) {
    val db: Database =
      if (args(0) == "student")
        StudentDatabase
      else
        SimpleDatabase

    /**
     * runtime to determine with database used for fetching recipes
     * student: StudentDatabase
     * simple: SimpleDatabase
     */
    object browser extends Browser {
      val database = db
    }

    val apple = SimpleDatabase.foodNamed("Apple").get

    // print recipes
    for (recipe <- browser.recipesUsing(apple))
      println(recipe)

    // error
    // Error:(33, 31) type mismatch;
    //    found   : db.FoodCategory
    //    required: browser.database.FoodCategory
    //    browser.displayCategory(category)
    //    ^
//    for (category <- db.allCategories)
//      browser.displayCategory(category)
  }

}
